package com.example.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void jumB(View view) {
        //方式一 putExtra
//        Intent intent = new Intent(this, ActivityB.class);
//        intent.putExtra("name","张三");
//        intent.putExtra("age",18);
//        startActivity(intent);

        //方式二
        Intent intent = new Intent(this, ActivityB.class);
        Bundle bundle = new Bundle();
        bundle.putString("name","李四");
        bundle.putInt("age",20);
        intent.putExtras(bundle);
//        startActivity(intent);
        startActivityForResult(intent,100);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == 100){
            String result = data.getStringExtra("result");
            Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
        }
    }
}